<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改品牌')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-brand-edit" th:object="${brand}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">品牌名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">品牌图标访问路径：</label>
                <div class="col-sm-8">
                    <button type="button" class="layui-btn" id="upload_url">上传图片</button>
                    <div class="layui-upload-list">
                        <div id="img_backgroundUrl" style="padding: 5px;"><img th:src="*{url}" style='height: 60px;width: 60px'></div>
                        <input type="hidden" id="url" name="url" th:field="*{url}">
                        <input type="hidden" id="urlReal" name="urlReal" th:field="*{urlReal}">
                        <p id="show_url"></p>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">介绍：</label>
                <div class="col-sm-8">
                    <textarea name="note" class="form-control">[[*{note}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" th:field="*{sort}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">品牌地址：</label>
                <div class="col-sm-8">
                    <input name="httpUrl" th:field="*{httpUrl}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/brand";
        $("#form-brand-edit").validate({
            focusCleanup: true,
            rules:{
                sort:{
                    digits: true
                }
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-brand-edit').serialize());
            }
        }


        layui.use('upload', function() {
            var $ = layui.jquery
                , upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#upload_url'
                , url: '/common/upload' //改成您自己的上传接口
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#show_url").html("<img src='" + res.url + "' style='width:80px;height:80px;'>");
                    $("#url").val(res.url);
                    $("#urlReal").val(res.realPath);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#show_url');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        })



    </script>
</body>
</html>